package org.lq.his.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.lq.his.pojo.Permission;
import org.lq.his.service.PermissionService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("/permission")
public class PermissionController {
	
	@Resource
	private PermissionService permissionService;

	public void setPermissionService(PermissionService permissionService) {
		this.permissionService = permissionService;
	}
	
	@RequestMapping("/index")
	public String PermissionIndex() throws Exception{
		
		return "permission/permissionIndex";
	}
	
	@RequestMapping("/permissionForm")
	public String PermissionParentFrom() throws Exception{
		
		return "permission/permissionForm";
	}
	
	@RequestMapping("/permissionAll")
	@ResponseBody
	public List<Permission> getAll() throws Exception{
		
		return permissionService.getAll();
	}
	
	@RequestMapping("/permissionAdd")
	@ResponseBody
	public Map<String,Object> addPermission(Permission permission) throws Exception{
		Map<String, Object> map = new HashMap<>();
		permissionService.add(permission);
		map.put("result", true);
		return map;
	}
	
	@RequestMapping("/permissionEdit")
	@ResponseBody
	public Map<String, Object> editPermission(Permission permission) throws Exception{
		Map<String, Object> map = new HashMap<>();
		permissionService.update(permission);
		map.put("resule", true);
		return map;
	}
	
	@RequestMapping("/permissionById")
	@ResponseBody
	public Permission getById(Integer id) throws Exception{
		
		return permissionService.getById(id);
	}
	
	@RequestMapping("/permissionDelete")
	@ResponseBody
	public Map<String, Object> deletePermissionsById(Integer id) throws Exception{
		Map<String, Object> map = new HashMap<>();
		permissionService.deletePermissionsById(id);
		map.put("result", true);
		return map;
	}
	
	@RequestMapping("/permissionId")
	@ResponseBody
	public List<Permission> getPermissionId(Integer id) throws Exception{
		
		return permissionService.getPermissionId(id);
	}
}
